guitarherofandomcom-20200222-history
Help:Parameter default
Note: Information on this page relates to MediaWiki versions 1.6 and later. Notation: on this page the wikitext } is written as a. In a template, b is equal to a if that is defined, and else equal to b. These results a and b can be end results, but they can also be parameter names, parameter values, template names, parts thereof, etc. If the results are template names as part of template calls involving a parameter of the outer template which may be undefined, one can arrange that an inner template is called with a parameter depending on an undefined outer parameter only if the parameter concerned is not actually used in the inner template, e.g. dummy template can be called as even if a is undefined, see e.g. . Limitation In the case of multiple default parts, only the first applies: b|c|d is equivalent with b. The default part can only contain "|" as part of full template, parameter or link syntax within it, and within nowiki-tags. Note that "|" can be avoided in table syntax by applying HTML coding (element " } } }}} }}} }}}} }}}} } } |b}}} |b}}} }|c}}} }|c}}} } } }}} }}}i''i'i''''i'i'i''''i'i'i''''i'i'i''''i'i'i''''i'i'i''''i'i'i''''i'i'i'i'' ... } | ... }}} } |pv= } |s= } |pc1= } |pc2= } |pc3= } |pc4= }| 1= }|2= }|3= } }} }| }| }| }| }| }| }= }}}}}} }| } }| }| }| }| }| }= }}}}}} }| } }| }| }| }| }| }= }}}}}}[ v[i''] | s ][v[i''|@] | sep ]f(x) = sep [v[i''|@] | sep] [v[''i|@] | ] }| }| }}}}}}} [3|[2|[1|*]]] [[ifu|3]| [[ifu|2]| [[ifu|1]| [[ifu|0]|*] //this line is actually useless, can be replaced by "*". ] ] ] 4321xxx-1x "). The expression for the parameter name can also contain "|", as part of full template or parameter syntax within it. Examples, using and : * gives * gives * gives * gives * gives - parameter aaa is undefined * gives - parameter b is undefined * gives - works fine for rendering text, but is not suitable for putting parameters b and c in a template call (there is no function for removing nowiki tags): *: gives Expressions containing a parameter, with default Consider the expression [ac|f(b)] occurring in a template, where f(b) denotes an expression in b. Conditions: *[ab] is undefined for all applicable b (all values of parameter b for which the template is called) *ac=d (the template is called with ac=d) Then the expression gives f(b) if b is defined, and otherwise d. Note that the conditions require that no applicable b has value c. If one wants to be able to use all letters and digits in b, and also allow null (the empty string), then for c one can take e.g. "@". If it is desirable or at least acceptable that if b is empty, the result is not f("") but "", and the same when b is undefined, we take d="", and can for example choose c to be the empty string too. Then we have the expression [ab|f(b)] occurring in the template, giving f(b) if b is defined, and otherwise the empty string, under the following conditions: *[ab] is undefined for all applicable b (all values of parameter b for which the template is called) *the template is called with "a=" The same template can contain several expressions [b | c | f (b)]. By choosing all a equal we need only one "a=" in the template call. Then the expressions are [b | c | f (b)]. A special case is with constant functions f, i.e. not dependent on b. Then the expressions are [b | c | f ]. In the template call it only matters for each b whether is gets a value, not which value. For convenience we can assign the empty string to those which are defined at all. Since no applicable b should have value c (see above), c should not be the empty string in this case. With d the empty string, the template serves as an array, where for index b the array value is f. It is called with "ac=" and "b=", or even with a list of assignments "b=", giving a list of the corresponding array values. See . While normally a parameter specification in a template call represents a choice the user of the template has, the need to specify "ac=" is an unfortunate technical requirement imposed on the user of the template; it can be shielded from the user by putting the template call inside another template; on projects where server-strain is a concern this may not be desirable. The name "a" can be chosen such that no other parameters of the template have a name starting with it, then the first condition is fulfilled (apart from the case, already discussed, that b is the empty string). A good choice is "if". Thus :[b | c | f (b)] means :if b is defined then f (b) c="" gives the if-statement which is shortest and with the best appearance, while e.g. c="u" (for "undefined") allows for the shortest specification in the template call to define b ("b=") in cases where the value is irrelevant. The latter may be confusing in contexts where "empty" and "undefined" are usually treated as equivalent. If the result, f(b) or the empty string, is for final display only, i.e., not for use in expressions for template names, parameter names, parameter values, page names in links, etc., an alternative is using CSS, see MediaWiki talk:Common.css. For comparison using a="if" and c=d="", and also the shorter class name "if" instead of "HiddenStructure", the two lines are: In the second method the wikitext in the template is 15 characters shorter for each optional item, but each call is 4 characters ("if=|") longer. In the first method conflicts with other class names have to be avoided, in the second method conflicts with other parameter names. Repetition A "for-loop" is achieved using , containing: ---- ---- with , containing: ---- ---- In short form the latter consists of components (''i = 1, 2, 3, for i'' = 1 without s) or in terms of the parameters of the first template: This is indeed of the above-mentioned form [ac|f(b)], with a=v, b=''i, c=@, and The assumptions mentioned above apply for d equal to null, and provided that no [i''] is equal to "@". Variations Since v@=null we can also take make the concatenation the outer operation: Conditional statement contains: ---- ---- or in short form: [ elsetest | [ testtest | then ] ] If test is defined this reduces to [ elsetest | [ testtest | then ] ] For test equal to null this reduces to else; otherwise, if no parameter name starting with "test" or "else" applies except these themselves, then this reduces to then. If test is undefined we get [ else | then ] Last-but technique Somewhen maybe the last or last but ''x parameter value is needed, but number of inputted parameter is unknown. The following is a technique to get last "assigned" parameter value without using a template: . Then last but one can be achieved like this: ("ifu" is preassigned with empty) I.e., to replace "4", "3", "2", "1" with D, D, D, D. And D=[if[|u]|]. Like this, you can get "last but " parameter value. Examples using and : * gives . * gives . * gives . * gives . * gives . * gives . * gives . * gives (finds maximum of a list of integers in the range 1 - 100) See also Server efficiency Parameter default constructs are said to be more efficiently executed by the server than similar constructs using extra layers of templates. See also * - examples References